package practice4;

import java.util.Scanner;

public class P2304 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ans=0;
        for(int i=1;i<=n;i++){
            String str = Integer.toString(i);
            if(str.contains("2")||str.contains("0")||str.contains("1")||str.contains("9")){
                ans+=i;
            }
        }
        System.out.println(ans);
    }
}
